/**
 * 
 */
package com.idea.zd.sys.util;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;

import com.idea.zd.sys.controller.PermissionController;
import com.jfinal.log.Logger;

/**
 * @author yzz
 * @create 2017年1月9日 下午4:40:31
 */
public class CreateFile {
	
	
	
	private static final Logger log = Logger.getLogger(PermissionController.class);
	
	/*
	 * 读取文件
	 */
	private static String readFile(String filePath)
    {
        // 读取txt内容为字符串
        StringBuffer txtContent = new StringBuffer();
        // 每次读取的byte数
        byte[] b = new byte[8 * 1024];
        InputStream in = null;
        try
        {
            // 文件输入流
            in = new FileInputStream(filePath);
            while (in.read(b) != -1)
            {
                // 字符串拼接
                txtContent.append(new String(b));
            }
            // 关闭流
            in.close();
        }
        catch (FileNotFoundException e)
        {
        	log.error("文件不存在");
            e.printStackTrace();
        }
        catch (IOException e)
        {
            // TODO Auto-generated catch block
        	log.error("文件读取异常");
            e.printStackTrace();
        }
        finally
        {
            if (in != null)
            {
                try
                {
                    in.close();
                }
                catch (IOException e)
                {
                    // TODO Auto-generated catch block
                	log.error("关闭输入流失败");
                    e.printStackTrace();
                }
            }
        }
        log.info("文件读取成功");
        return txtContent.toString();
    }
	
	
	/*
	 * 生成文件
	 */
	public static void createFile(String str,String jspName,String path){
		 try{
		      File file =new File(path + jspName);

		      //if file doesnt exists, then create it
		      if(!file.exists()){
		       file.createNewFile();
		      }

		      //true = append file
		      BufferedWriter out = new BufferedWriter(new FileWriter(
		    		  file, true));
				out.write(str);
				out.close();
	
	          log.info("文件生成成功");
		     }catch(IOException e){
		      e.printStackTrace();
		      log.error("生成文件失败");
		     }
		    
	}
	
	
	//把一个字符串中的大写转为小写
	private static String firstLower(String str){  
	    for(int i=0;i<1;i++){
	    	str = str.replace(str.substring(0,1), str.substring(i, i+1).toLowerCase());
	    	System.out.println(str);
	    }  
	    return str;  
	}  
	
	public static void main(String[] args) {
		/*JSPEntity jsp = new JSPEntity();
		jsp.setJspName("userTest");
		jsp.setTableName("用户列表");
		jsp.setTile("用户列表");
		List<Search> sl = new ArrayList<Search>();
		Search s = new Search();
		s.setParamName("name");
		s.setText("名字");
		s.setType("1");
		sl.add(s);
		Search s1 = new Search();
		s1.setParamName("datetime");
		s1.setText("日期范围");
		s1.setType("2");
		sl.add(s1);
		Search s2 = new Search();
		s2.setParamName("date");
		s2.setText("日期");
		s2.setType("3");
		sl.add(s2);
		jsp.setSearchs(sl);
		List<TableColunm> tcl = new ArrayList<TableColunm>();
		TableColunm tc = new TableColunm();
		tc.setTableName("user_name");
		tc.setText("用户名");
		tc.setType("1");
		tcl.add(tc);
		TableColunm tc1 = new TableColunm();
		tc1.setTableName("user_name2");
		tc1.setText("用户名2");
		tc1.setType("1");
		tcl.add(tc1);
		TableColunm tc2 = new TableColunm();
		tc2.setTableName("user_name3");
		tc2.setText("用户名3");
		tc2.setType("1");
		tcl.add(tc2);
		jsp.setColunms(tcl);
		
		ControllerCol cc = new ControllerCol();
		cc.setAdd("1");
		cc.setDel("1");
		jsp.setControllerCol(cc);
		jsp.setModel("User");
		//createJSP(jsp);
		createListJs(jsp);*/
		/*String modelStr = readFile(MODELPATH+"Administrator.java");
		System.out.println(modelStr.substring(modelStr.indexOf("pkName=\"")+8,modelStr.indexOf("\")")));
		System.out.println(BATCHDELFUNCTION);*/
		String s = "爱我中国";
		char[] chars = s.toCharArray();
		for(char cs:chars){
			System.out.println(cs);
		}
	}
}
